package com.group56.viewmodel.dto;

import com.group56.model.dao.CoachDAO;
import com.group56.model.dao.CustomerDAO;
import com.group56.model.dao.Impl.CoachDAOImpl;
import com.group56.model.dao.Impl.CustomerDAOImpl;
import com.group56.model.entity.Customer;
import com.group56.model.entity.Schedule;
import com.group56.view.coachend.schedule_module.ScheduleRectController;
import com.group56.view.coachend.schedule_module.ScheduleRectController.STATUS;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;


public class ScheduleDTO {
    private StringProperty scheduleID = new SimpleStringProperty();
    private StringProperty date = new SimpleStringProperty();
    private StringProperty time = new SimpleStringProperty();
    private StringProperty customerID = new SimpleStringProperty();
    private StringProperty coachID = new SimpleStringProperty();

    private ObjectProperty<STATUS> status;

    private StringProperty coachName = new SimpleStringProperty();
    private CustomerDTO customerDTO;


    public void update(STATUS status, Schedule schedule){
        this.status = new SimpleObjectProperty<>(status);
        this.date.set(schedule.getDate());
        this.time.set(schedule.getTime());
        if(status==STATUS.BOOKED || status==STATUS.UNAVAILABLE) {
            this.scheduleID.set(schedule.getScheduleID());
            this.coachID.set(schedule.getCoachID());
            this.customerID.set(schedule.getCustomerID());
            if(!schedule.getCustomerID().equals("-1")) {//如果是unavailable的schedule，则该schedule的customer为-1
                CoachDAO coachDAO = new CoachDAOImpl();
                CustomerDAO customerDAO = new CustomerDAOImpl();

                this.coachName.set(coachDAO.selectByID(coachID.get()).getName());
                Customer customer = customerDAO.selectByID(customerID.get());
                this.customerDTO = new CustomerDTO(customer);
            }
        }//否则status为有空/没有预约，schedule的信息都为null
    }

    public ScheduleDTO(STATUS status, Schedule schedule) {
        update(status, schedule);
    }

    public String getScheduleID() {
        return scheduleID.get();
    }

    public StringProperty scheduleIDProperty() {
        return scheduleID;
    }

    public void setScheduleID(String scheduleID) {
        this.scheduleID.set(scheduleID);
    }

    public String getDate() {
        return date.get();
    }

    public StringProperty dateProperty() {
        return date;
    }

    public void setDate(String date) {
        this.date.set(date);
    }

    public String getTime() {
        return time.get();
    }

    public StringProperty timeProperty() {
        return time;
    }

    public void setTime(String time) {
        this.time.set(time);
    }

    public String getCustomerID() {
        return customerID.get();
    }

    public StringProperty customerIDProperty() {
        return customerID;
    }

    public void setCustomerID(String customerID) {
        this.customerID.set(customerID);
    }

    public String getCoachID() {
        return coachID.get();
    }

    public StringProperty coachIDProperty() {
        return coachID;
    }

    public void setCoachID(String coachID) {
        this.coachID.set(coachID);
    }

    public STATUS getStatus() {
        return status.get();
    }

    public ObjectProperty<STATUS> statusProperty() {
        return status;
    }

    public void setStatus(STATUS status) {
        this.status.set(status);
    }

    public String getCoachName() {
        return coachName.get();
    }

    public StringProperty coachNameProperty() {
        return coachName;
    }

    public void setCoachName(String coachName) {
        this.coachName.set(coachName);
    }

    public CustomerDTO getCustomerDTO() {
        return customerDTO;
    }

    public void setCustomerDTO(CustomerDTO customerDTO) {
        this.customerDTO = customerDTO;
    }
}
